package dp.leetcode_53;

public class BestDP {
    public int maxSubArray(int[] nums) {
        int pre = nums[0];
        int res = 0;
        for (int i = 0; i < nums.length; i++) {
            if (pre + nums[i] > nums[i]) {
                pre = pre + nums[i];
            } else {
                pre = nums[i];
            }
            res = Math.max(res, pre);
        }
        return res;
    }
}
